/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package smartgym.gui.tables;

import java.text.SimpleDateFormat;
import java.util.List;
import javax.swing.table.DefaultTableModel;
import smartgym.models.entities.Payment;

/**
 *
 * @author Carlos
 */
public class PaymentTableFrame extends TableFrameBase implements TableInterface{
    
    List<Payment> paymentList;
    /**
     * Creates new form PaymentTableFrame
     */
    public PaymentTableFrame() {
        super();
        //initComponents();
        this.setTableHeader(new String[]{"Codigo", "Client", "Vencimento","Valor", "status"});
        getObjectTable().setModel(new DefaultTableModel(new Object[0][0], getTableHeader()));
        getObjectTable().setVisible(true);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables

    @Override
    public Object getSelectRow() {
        int index = this.getObjectTable().getSelectedRow();
        return this.paymentList.get(index);
    }

    @Override
    public void fillTable() {
        Object[][] dados = new Object[paymentList.size()][getTableHeader().length];

        for (int i = 0; i < paymentList.size(); i++) {
            Payment payment = (Payment) paymentList.get(i);
            dados[i][0] = payment.getId();
            dados[i][1] = payment.getClient().getName();
            dados[i][2] = new SimpleDateFormat("dd/MM/yyyy").format(payment.getMaturity());
            dados[i][3] = "R$ "+payment.getPaymentValue();
            if(payment.isPaid()){
                dados[i][4] = "Pago";
            }else{
                dados[i][4] = "Pedente";
            }
            
            getObjectTable().setModel(new DefaultTableModel(dados, this.getTableHeader()));

        }
    }

    @Override
    public void setObjectList(List object) {
        this.paymentList = (List<Payment>)object;
        fillTable();
    }

    

    
}
